package com.tucc.hello.leetcode.no1_400.no1_200.no1_20.no1_10.no6;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();

    }

    public String convert(String s, int numRows) {
        if (numRows == 1 || numRows > s.length()) {
            return s;
        }
        int step = (numRows - 1) * 2;
        StringBuilder str = new StringBuilder();
        int st = 0;
        while (st < s.length()) {
            str.append(s.charAt(st));
            st += step;
        }
        for (int i = 1; i < numRows - 1; i++) {
            int gap = step - i * 2;
            int index = i;
            while (index < s.length()) {
                str.append(s.charAt(index));
                index += gap;
                gap = step - gap;
            }
        }
        st = numRows - 1;
        while (st < s.length()) {
            str.append(s.charAt(st));
            st += step;
        }
        return str.toString();
    }
}
